package com.limingru.newbee.api;

import com.limingru.newbee.api.vo.IndexCarouselVO;
import com.limingru.newbee.api.vo.IndexConfigGoodsVO;
import com.limingru.newbee.api.vo.IndexInfoVO;
import com.limingru.newbee.common.IndexConfigEnum;
import com.limingru.newbee.service.CarouselService;
import com.limingru.newbee.service.IndexConfigService;
import com.limingru.newbee.util.Result;
import com.limingru.newbee.util.ResultGenerator;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "v1", tags = "新蜂商城首页")
@RequestMapping("/api/v1")
public class IndexAPI {
    @Resource
    CarouselService carouselService;

    @Resource
    IndexConfigService indexConfigService;

    @GetMapping("/index/info")
    public Result<IndexInfoVO> getIndexInfo() {
        IndexInfoVO indexInfoVO = new IndexInfoVO();
        List<IndexCarouselVO> carouselList = carouselService.getCarouselList();
        List<IndexConfigGoodsVO> configHotGoods = indexConfigService.getConfigGoods(IndexConfigEnum.INDEX_GODDS_HOT.getType());
        List<IndexConfigGoodsVO> configNewGoods = indexConfigService.getConfigGoods(IndexConfigEnum.INDEX_GOODS_NEW.getType());
        List<IndexConfigGoodsVO> configRecommendGoods = indexConfigService.getConfigGoods(IndexConfigEnum.INDEX_GOODS_RECOMMEND.getType());
        indexInfoVO.setCarousels(carouselList);
        indexInfoVO.setHotGoods(configHotGoods);
        indexInfoVO.setNewGoods(configNewGoods);
        indexInfoVO.setRecommendGoods(configRecommendGoods);
        return ResultGenerator.generateSuccessResult(indexInfoVO);
    }
}
